﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Candy.Infrastructure
{
       public class CaretBrushFixBehavior
    {
        // Dependency property and setter/getter
        public static DependencyProperty CaretBrushProperty = DependencyProperty.RegisterAttached(
                                                                                                "CaretBrush", typeof(SolidColorBrush)
                                                                                                , typeof(CaretBrushFixBehavior)
                                                                                                , new PropertyMetadata(CaretBrushPropertyChanged));

        public static void SetCaretBrush(DependencyObject obj, SolidColorBrush toUpper_) { obj.SetValue(CaretBrushProperty, toUpper_); }
        public static SolidColorBrush GetCaretBrush(DependencyObject obj) { return (SolidColorBrush)obj.GetValue(CaretBrushProperty); }

        // When value set to true on TextBlock or ContentControl add loaded event to control
        public static void CaretBrushPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is TextBox)
            {
                (d as TextBox).CaretBrush = new SolidColorBrush((e.NewValue as SolidColorBrush).Color);
            }
            if (d is PasswordBox)
            {
                (d as PasswordBox).CaretBrush = new SolidColorBrush((e.NewValue as SolidColorBrush).Color);
            }
        }
    }

}
